
//得到阈值
/*console.log(threshold);
var j = parseInt(threshold);
console.log(j);*/
//勾画整体布局
var left_1 = document.getElementById("left_1");
var left_2 = document.getElementById("left_2");
var left_3 = document.getElementById("left_3");

var center_1 = document.getElementById("center_1");
var center_2 = document.getElementById("center_2");

document.getElementById('right').innerHTML = '<div id="right_1" style="border-style: solid; border-width: 32px 37px; border-image-slice: 32 37 fill; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; background: none;border-image-source:url(\'image/kuang.png\');height: 305px"></div><div style="height: 20px"></div><div id="right_2" style="border-style: solid; border-width: 16px 18px; border-image-slice: 32 37 fill; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; background: none;border-image-source:url(\'image/kuang.png\');height: 312px"></div><div style="height: 20px"></div><div id="right_3" style="border-style: solid; border-width: 16px 18px; border-image-slice: 32 37 fill; border-image-width: initial; border-image-outset: initial; border-image-repeat: initial; background: none;border-image-source:url(\'image/kuang.png\');height: 305px"></div>';
var right_1 = document.getElementById("right_1");
var right_2 = document.getElementById("right_2");
var right_3 = document.getElementById("right_3");

//勾画左一区域
left_1.innerHTML = '<h4 align="center" style="color:#EBD775">CPU使用</h4>';
getCanvas('cpuUse', left_1);//得到echarts画布
getCpuEcharts();//得到echarts图表
getCpuInfo();//给Echarts注入数据
setInterval(function() {
	getCpuInfo();
}, 15000);//更新数据

//勾画左二区域
left_2.innerHTML = '<h4 align="center" style="color:#EBD775">内存使用</h4>';
getCanvas('memUse', left_2);
getMemEcharts();
getmemInfo();
setInterval(function() {
	getmemInfo();
}, 15000);

//勾画左三区域
left_3.innerHTML = '<h4 align="center" style="color:#EBD775">磁盘使用</h4>';
getCanvas('diskUse', left_3);
getDiskEcharts();
getDIskInfo();
setInterval(function() {
	option_left3.yAxis[0].data.length=0;
	for (var i = 0; i < keys.length; i++) {
		option_left3.series[i].data.length=0;
	}
	freshDIskInfo();
}, 15000);
//勾画右一区域
right_1.innerHTML = '<h4 align="center" style="color:#EBD775">应用连接数</h4>';
getCanvas('appConn', right_1);
getAppConnNumEcharts();
getAppConnNum();
setInterval(function() {
	freshAppConnNum();
}, 15000);
//勾画右二区域
right_2.innerHTML = '<h4 align="center" style="color:#EBD775;margin-top: 5%">应用状态</h4>';
getCanvas('appStatus', right_2);
getTable();
getStatus();
setInterval(function() {
	freshStatus();
}, 15000);
//勾画右三区域
right_3.innerHTML = '<h4 align="center" style="color:#EBD775;margin-top: 5%">表空间使用率</h4>';
getCanvas('tableUser', right_3);
getTableUserEcharts();
gettableUserData();
setInterval(function() {
	gettableUserData();
}, 15000);

//勾画中二区域
getCanvas('topological', center_2);
getTopological();

//滚动条
//中一滚动条
var center_1 = document.getElementById('center_1');
var cp = document.createElement('div');
cp.setAttribute('style', "width:700px; height:40px; position: absolute;left:81px;top:100px;");
cp.innerHTML='<marquee id="gdt" direction="left" onmouseover="this.stop();" onmouseout="this.start();" style="font-size: 30px; color:red"></marquee>';
//contenteditable="true" 可编辑滚动
var warnning = '';
center_1.appendChild(cp);
setInterval(function() {
	document.getElementById('gdt').innerText=warnning;
}, 15000);


//得到网络拓扑图
function getTopological() {
    var nodes = null;
    var edges = null;
    var network = null;

 //   var DIR = '../img/refresh-cl/';
    var EDGE_LENGTH_MAIN = 150;
    var EDGE_LENGTH_SUB = 130;

    // Called when the Visualization API is loaded.
      // Create a data table with nodes.
    $.post('ServerInfo/getAllserverInfoByIp',{},function(data){
    	var data = data.data;
    	nodes = [];
    	var nodeId=2;
    	var esb;
    	var mysql;
    	var oracle=[];
    	var appId=[];
    	// Create a data table with links.
    	edges = [];
    	//nodes.push({id: 1, label: '', image:'image/host.png', shape: 'image'});
    	for ( var key in data) {
    		var appkey = 1;
    		var appIp = '';
    		var app='';
    		for ( var key1 in data[key]) {
				if(data[key][key1].name=='ESB'){
					nodes.push({id: nodeId, label: key+'\n中医馆数据交汇', image:'image/server.png', shape: 'image'});
					//edges.push({from: 1, to: nodeId, length: 90});
					esb=nodeId;
				}else if (data[key][key1].name=='MYSQL') {
					nodes.push({id: nodeId, label: key+'\nMYSQL', image:'image/server.png', shape: 'image'});
					oracle.push(nodeId);
				}else if (data[key][key1].name=='ORACLE') {
					nodes.push({id: nodeId, label: key+'\nORACLE', image:'image/server.png', shape: 'image'});
					oracle.push(nodeId);
				}else {
					if(appkey==1){
						appIp=key;
						appkey+=1;
					}
					app+=data[key][key1].name+'\n';
				}
			}
    		if (key==appIp) {
    			nodes.push({id: nodeId, label: key+app, image:'image/server.png', shape: 'image'});
    			appId.push(nodeId);
			}
    		nodeId+=1;
    	}
    	for (var int = 0; int < appId.length; int++) {
    		edges.push({from: esb, to: appId[int], length: EDGE_LENGTH_SUB});
		}

    	for (var int2 = 0; int2 < oracle.length; int2++) {
			edges.push({from: esb, to: oracle[int2], length: EDGE_LENGTH_SUB});
		}

    	// create a network
    	var container = document.getElementById('topological');
    	var data = {
    			nodes: nodes,
    			edges: edges
    	};
    	var options = {
    			nodes:{
    				font: {//字体配置
    					color: '#EEE',//颜色
    					size: 13, // 大小，单位px
    					face: 'arial',//字体
    					background: 'none',//背景
    					align: 'left',//位置left right center
    				},
    			},
    	};
    	network = new vis.Network(container, data, options);
    });
}
//得到表空间使用率图表
function getTableUserEcharts() {
	right3Chart = echarts.init(tableUser);
	option_right3 = {
		color: ['#277ACE'], //可选色：'#86D560', '#AF89D6', '#59ADF3', '#FF999A',
		// '#FFCC67'
		tooltip : {
			trigger : 'axis',
			axisPointer : { // 坐标轴指示器，坐标轴触发有效
				type : 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		grid : {
			left : '0%',
			top : '3%',
			right : '10%',
			bottom : '37%',
			containLabel : true
		},
	    legend: {
	    	data:[],
	        itemWidth:11,
	        itemHeight:10,
			textStyle:{
				color:'#eee',
				fontSize:10,
			},
			top:'93%'
	    },
		xAxis : [ {
			type : 'category',
			data : [],
			splitLine : {
				"show" : false
			},
			axisTick : {
				"show" : false
			},
			splitArea : {
				"show" : false
			},
			axisLabel : {
				interval : 0,
				rotate : -70,
				align : 'left',
				show : true,
				splitNumber : 15,
				textStyle : {
					fontFamily : "微软雅黑",
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		yAxis : [ {
			type : 'value',
			min : 0,
			max : 100,
			splitLine : {
				lineStyle : {
					color : '#284190'
				}
			//show:false
			},
			axisLabel : {
				formatter : '{value}%',
				textStyle : {
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		series : [{
			name : '表空间使用率',
			type : 'bar',
			barWidth : '33%',
			barGap:0,
			data : [],
			itemStyle:{
				normal:{
					barBorderRadius: 50,
				}
			},
			label : {
				normal : {
					show : false,
					formatter : '{c}%',
					position : 'top',
					textStyle : {
						fontSize : 10
					}
				}
			},
		},]
	};
}
//得到表空间使用率数据
function gettableUserData() {
	$.post('OracleInfo/getOracleTableUserInfo',{},function(data){
		var data = data.data;
		for ( var key in data) {
			option_right3.xAxis[0].data.push(key);
			if(data[key]>parseInt(oracletablespaceused)){
				option_right3.series[0].data.push({
					value : data[key],
					itemStyle : {
						normal : {
							color : '#c23531'
						}
					}
				});
				var hour = new Date().getHours();
				var minute = new Date().getMinutes();
				var second = new Date().getSeconds();
				prompt('<p class="">'+[hour,minute,second].join(':')+'</p>&nbsp;'
						+'<p class="">'+ key+'</p>的表空间使用率已达到'
						+data[key]);
				warnMusic();
				warnning+=key+'的表空间使用率已达到'+data[key]+' ';
			}else {
				option_right3.series[0].data.push({
					value : data[key],
					itemStyle : {
						normal : {
							color : '#277ACE'
						}
					}
				});
			}
		}
		right3Chart.setOption(option_right3);
	});
	option_right3.xAxis[0].data.length=0;
	option_right3.series[0].data.length=0;
}

//勾画应用状态表格
function getTable() {
	var table = '<table class="table table-bordered" style="width=476px;height=240px;margin-top:-5%; color: #6C6C6C;"><tr><td id="server1" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server2" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server3" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server4" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td></tr>'
				+'<tr><td id="server5" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server6" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server7" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server8" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td></tr>'
				+'<tr><td id="server9" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server10" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server11" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td><td id="server12" width="119px" height="80px" bgcolor="#56D1FD" style="border: 2px solid #121F50 !important; "></td></tr>'
				+'</table>';
	appStatus.innerHTML = table;
}

//得到各系统服务状态和端口状态
function getStatus() {
	$.post('connInfo/getNewAllAppStatus',{},function(data){
		var data = data.data;
		var statusmap = data[0];
		var portStutas = data[1];
		var i=1;
		var j=1;
		for ( var key in statusmap) {
			var position = document.getElementById("server"+i);
			if(key=='数据库'){
				var serverName = document.createElement('h5');
				var serverstatus = document.createElement('h5');
				serverName.innerHTML='<h5 style="font-weight:bold;" id="serverName'+i+ '">'+key+'</h5>';
				position.appendChild(serverName);
				for ( var key2 in statusmap[key]) {
					if(statusmap[key][key2]== service){
						serverstatus.innerHTML='<h5 id="serverstatus'+i+ '">服务未启动</h5>';
						position.appendChild(serverName);
						position.appendChild(serverstatus);
						var hour = new Date().getHours();
						var minute = new Date().getMinutes();
						var second = new Date().getSeconds();
						position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
						prompt([hour,minute,second].join(':')+'&nbsp;'+  key2+'的服务未启用');
						warnMusic();
						warnning+=key2+'的服务未启用'+' ';

					}else {
						serverstatus.innerHTML='<h5 id="serverstatus'+i+ '">服务正常</h5>';
						position.appendChild(serverName);
						position.appendChild(serverstatus);
					}
				}
			}else {
				var serverName = document.createElement('h5');
				var serverstatus = document.createElement('h5');
				serverName.innerHTML='<h5 style="font-weight:bold;" id="serverName'+i+ '">'+key+'</h5>';
				if(statusmap[key] == 'off'){
					serverstatus.innerHTML='<h5 id="serverstatus'+i+ '">服务未启动</h5>';
					position.appendChild(serverName);
					position.appendChild(serverstatus);
					var hour = new Date().getHours();
					var minute = new Date().getMinutes();
					var second = new Date().getSeconds();
					position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
					prompt([hour,minute,second].join(':')+'&nbsp;'+  key+'的服务未启用');
					warnning+=key+'的服务未启用'+' ';
					warnMusic();
				}else {
					serverstatus.innerHTML='<h5 id="serverstatus'+i+ '">服务正常</h5>';
					position.appendChild(serverName);
					position.appendChild(serverstatus);
				}
			}
			i++;
		}
		for ( var key in portStutas) {
			if(key=='数据库'){
				for ( var key1 in portStutas[key]) {
					for ( var key2 in portStutas[key][key1]) {
						if(portStutas[key][key1][key2]==portStatus){
							if(statusmap[key][key1]!=service){
								var position = document.getElementById("server"+j);
								document.getElementById("serverstatus"+j).innerHTML=key1+key2+'端口未开启';
								position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
								var hour = new Date().getHours();
								var minute = new Date().getMinutes();
								var second = new Date().getSeconds();
								prompt([hour,minute,second].join(':')+'&nbsp;'+ key1+'的'+ key2+'的端口未启用');
								warnning+=key1+'的'+ key2+'的端口未启用'+' ';
								warnMusic();
							}
						}
					}
				}
			}else {
				for ( var key1 in portStutas[key]) {
					if(portStutas[key][key1]==portStatus){
						if(statusmap[key]!=service){
							var position = document.getElementById("server"+j);
							document.getElementById("serverstatus"+j).innerHTML='端口'+key1+'未开启';
							position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
							var hour = new Date().getHours();
							var minute = new Date().getMinutes();
							var second = new Date().getSeconds();
							prompt([hour,minute,second].join(':')+'&nbsp;'+ key+'系统'+ key1+'的端口未启用');
							warnning+=key+'的'+ key2+'的端口未启用'+' ';
							warnMusic();
						}
					}
				}

			}
			j++;
		}
	});
}
//刷新各系统服务状态和端口状态
function freshStatus() {
	$.post('connInfo/getNewAllAppStatus',{},function(data){
		var data = data.data;
		var statusmap = data[0];
		var portStutas = data[1];
		var i=1;
		var j=1;
		for ( var key in statusmap) {
			var position = document.getElementById("server"+i);
			if(key=='数据库'){
				var serverName = document.getElementById("serverName"+i);
				var serverstatus = document.getElementById("serverstatus"+i);
				serverName.innerHTML=key;
				for ( var key2 in statusmap[key]) {
					if(statusmap[key][key2]==service){
						serverstatus.innerHTML=key2+'服务未启动';
						var hour = new Date().getHours();
						var minute = new Date().getMinutes();
						var second = new Date().getSeconds();
						position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
						prompt([hour,minute,second].join(':')+'&nbsp;'+  key2+'的服务未启用');
						warnning+=key2+'的服务未启用'+' ';
						warnMusic();
					}else {
						serverstatus.innerHTML='服务正常';
						position.appendChild(serverName);
						position.appendChild(serverstatus);
					}
				}
			}else {
				var serverName = document.getElementById("serverName"+i);
				var serverstatus = document.getElementById("serverstatus"+i);
				serverName.innerHTML=key;
				if(statusmap[key] == service){
					serverstatus.innerHTML='服务未启动';
					var hour = new Date().getHours();
					var minute = new Date().getMinutes();
					var second = new Date().getSeconds();
					position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
					prompt([hour,minute,second].join(':')+'&nbsp;'+  key+'的服务未启用');
					warnning+=key+'的服务未启用'+' ';
					warnMusic();
				}else {
					serverstatus.innerHTML='服务正常';
					position.appendChild(serverName);
					position.appendChild(serverstatus);
				}
			}
			i++;
		}
		for ( var key in portStutas) {
			if(key=='数据库'){
				for ( var key1 in portStutas[key]) {
					for ( var key2 in portStutas[key][key1]) {
						if(portStutas[key][key1][key2]==portStatus){
							if(statusmap[key][key1]!=service){
								var position = document.getElementById("server"+j);
								document.getElementById("serverstatus"+j).innerHTML=key1+key2+'端口未开启';
								position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
								var hour = new Date().getHours();
								var minute = new Date().getMinutes();
								var second = new Date().getSeconds();
								prompt([hour,minute,second].join(':')+'&nbsp;'+ key1+'的'+ key2+'的端口未启用');
								warnMusic();
								warnning+=key1+'的'+ key2+'的端口未启用'+' ';
							}
						}
					}
				}
			}else {
				for ( var key1 in portStutas[key]) {
					if(portStutas[key][key1]==portStatus){
						if(statusmap[key]!=service){
							var position = document.getElementById("server"+j);
							document.getElementById("serverstatus"+j).innerHTML='端口'+key1+'未开启';
							position.setAttribute('style', 'border: 2px solid #121F50 !important;background-color:#FF5151');
							var hour = new Date().getHours();
							var minute = new Date().getMinutes();
							var second = new Date().getSeconds();
							prompt([hour,minute,second].join(':')+'&nbsp;'+ key+'系统'+ key1+'的端口未启用');
							warnMusic();
							warnning+=key+'系统'+ key1+'的端口未启用'+' ';
						}
					}
				}

			}
			j++;
		}
	});
}

//得到应用连接数图表
function getAppConnNumEcharts() {
	right1Chart2 = echarts.init(appConn);
	Option_right1 = {
		    tooltip : {
		        trigger: 'axis'
		    },
		    color: ['#C23531','#0000FF','#3398DB','#6A1512','#666633','#7FFFAA','#B5C334','#E87C25','#F3A43B','#FFFF00','#D7504B','#008000'],
		    /*title:{
		    	text:'各任务省份完成情况',
		    	left:'center',
		    	textStyle:{
		    		fontSize: 23,
		    	    fontWeight: 'bolder',
		    	    color: '#F4DB6F'
		    	}
		    },*/
			grid : {
				left : '0%',
				top : '5%',
				right : '10%',
				bottom : '20%',
				containLabel : true
			},
		    legend: {
		    	data:[],
		        itemWidth:11,
		        itemHeight:10,
				textStyle:{
					color:'#eee',
					fontSize:10,
				},
				top:'80%'
		    },
		    calculable : true,
		    xAxis : [
		        {
		            type : 'category',
		            boundaryGap : false,
		            data : [],
		            axisLabel: {
		            	clickable:true,
			            inside: false,
			            rotate:0,
			            textStyle: {
			                color: '#EEE',
			                fontSize:12
			            }
			        },
			        axisLine: {
		                show: true,
		                lineStyle:{
		                    color:'#EEE',
				    fontSize:14
		                }
		            },
		        }
		    ],
		    yAxis : [
		        {
		            type : 'value',
		            axisLabel: {
			            textStyle: {
			                color: '#EEE',
			                fontSize:12
			            }
			        },
			        axisLine: {
		                show: true,
		                lineStyle:{
		                    color:'#EEE',
				    fontSize:14
		                }
		            },
		        }
		    ],
		    series : []
		};
}
//得到应用连接数数据
function getAppConnNum() {
	$.post('connInfo/getAllConnNumList',{},function(data){
		var data = data.data;
		for ( var key in data) {
			if(key == 'time'){
				var times = data[key];
				for (var i = 0; i < times.length; i++) {
					var time = times[i];
					var hour = new Date(time*1000).getHours();
					var minute = new Date(time*1000).getMinutes();
					var second = new Date(time*1000).getSeconds();
					Option_right1.xAxis[0].data.push([hour,minute,second].join(':'));
				}
			}else {
				Option_right1.legend.data.push(key);
				Option_right1.series.push({
		            name:key,
		            type:'line',
		            itemStyle : { normal: {label : {show: false, position: 'insideRight'}}},
		            data:data[key],
		    	});
			}
		}
		right1Chart2.setOption(Option_right1);
	});
}
//刷新
function freshAppConnNum() {
	$.post('connInfo/getNewAllConnNum',{},function(data){
		var data = data.data;
		var conn = data[0];
		var maxConn = data[1];
		for ( var key in conn) {
			var time = conn[key];
			var hour = new Date(time*1000).getHours();
			var minute = new Date(time*1000).getMinutes();
			var second = new Date(time*1000).getSeconds();
			if(key == 'time'){
				if(Option_right1.xAxis[0].data.length<20){
					Option_right1.xAxis[0].data.push([hour,minute,second].join(':'));
				}else {
					Option_right1.xAxis[0].data.shift();
					Option_right1.xAxis[0].data.push([hour,minute,second].join(':'));
				}
			}else {
				for (var i = 0; i < Option_right1.series.length; i++) {
					if(conn[key] == maxConn[key]){
						prompt([hour,minute,second].join(':')+'&nbsp;'+  key+'的连接数已达到最大值' +maxConn[key]);
						warnMusic();
						warnning+=key+'的连接数已达到最大值' +maxConn[key]+' ';
					}
					if(Option_right1.series[i].name == key){
						if(Option_right1.series[i].data.length<20){
							Option_right1.series[i].data.push(conn[key]);
						}else {
							Option_right1.series[i].data.shift();
							Option_right1.series[i].data.push(conn[key]);
						}
					}
				}
			}
		}
		right1Chart2.setOption(Option_right1);
	});
}
//得到磁盘echarts图表
function getDiskEcharts() {
	left3Chart = echarts.init(diskUse);
	option_left3 = {
		color: ['#277ACE','#65f5f3'], //可选色：'#86D560', '#AF89D6', '#59ADF3', '#FF999A',
		// '#FFCC67'
		tooltip : {
			trigger : 'axis',
			axisPointer : { // 坐标轴指示器，坐标轴触发有效
				type : 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		grid : {
			left : '-5%',
			top : '0%',
			right : '10%',
			bottom : '10%',
			containLabel : true
		},
	    legend: {
	    	data:[],
	        itemWidth:11,
	        itemHeight:10,
			textStyle:{
				color:'#eee',
				fontSize:10,
			},
			top:'93%'
	    },
	    xAxis : [ {
	    	type : 'value',
	    	min : 0,
	    	max : 100,
	    	splitLine : {
	    		lineStyle : {
	    			color : '#284190'
	    		}
	    //show:false
	    	},
	    	axisLabel : {
	    		formatter : '{value}%',
	    		textStyle : {
	    			fontSize : 10,
	    			color : '#EEE',
	    		}
	    	},
	    } ],
		yAxis : [ {
			type : 'category',
			data : [],
			splitLine : {
				"show" : false
			},
			axisTick : {
				"show" : false
			},
			splitArea : {
				"show" : false
			},
			axisLabel : {
				interval : 0,
				rotate : 0,
				margin : 40,
				align : 'center',
				show : true,
				splitNumber : 15,
				textStyle : {
					fontFamily : "微软雅黑",
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		series : []
	};
}
//得到 磁盘数据
function getDIskInfo() {
	$.post('diskInfo/getAllDiskinfo', {}, function(data) {
		var data = data.data;
		keys = [];
		for ( var key1 in data) {
			option_left3.yAxis[0].data.push(key1);
			var diskInfo = data[key1];
			for ( var key2 in diskInfo) {
				if (diskInfo[key2].diskUsedPer>parseInt(diskUsed)) {
					if($.inArray(key2, keys)==-1){
						keys.push(key2);
						option_left3.legend.data.push(key2+'分区');
						option_left3.series.push({
							name : key2+'分区',
							type : 'bar',
							barWidth : '30%',
							barGap:0,
							data : [{
									value : diskInfo[key2].diskUsedPer,
									itemStyle : {
										normal : {
											color : '#c23531'
										}
									}
									}],
							label : {
								normal : {
									show : true,
									formatter : '{c}%',
									position: 'right',
									textStyle : {
										fontSize : 10
									}
								}
							},
						});
					}else {
						option_left3.series[$.inArray(key2, keys)].data.push(
								{
									value : diskInfo[key2].diskUsedPer,
									itemStyle : {
										normal : {
											color : '#c23531'
										}
									}

								});
					}
					prompt(key1+ '&nbsp;'+'服务器的'+ '磁盘' + key2+'分区的使用率已达到'+'&nbsp;' +diskInfo[key2].diskUsedPer+'%');
					warnMusic();
					warnning+=key1+'服务器的'+ '磁盘' + key2+'分区的使用率已达到'+diskInfo[key2].diskUsedPer+'%'+' ';
				}else {
					if($.inArray(key2, keys)==-1){
						keys.push(key2);
						option_left3.legend.data.push(key2+'分区');
						option_left3.series.push({
							name : key2+'分区',
							type : 'bar',
							barWidth : '30%',
							barGap:0,
							data : [{
								value : diskInfo[key2].diskUsedPer,
								itemStyle : {
									normal : {
										color : option_left3.color[$.inArray(key2, keys)]
									}
								}

							}],
							label : {
								normal : {
									show : true,
									formatter : '{c}%',
									position: 'right',
									textStyle : {
										fontSize : 10
									}
								}
							},
						});
					}else {
						option_left3.series[$.inArray(key2, keys)].data.push(
								{
									value : diskInfo[key2].diskUsedPer,
									itemStyle : {
										normal : {
											color : option_left3.color[$.inArray(key2, keys)]
										}
									}

								});
					}
				}
			}
		}
		left3Chart.setOption(option_left3);
	});
}

//刷新磁盘数据
function freshDIskInfo() {
	$.post('diskInfo/getAllDiskinfo', {}, function(data) {
		var data = data.data;
		for ( var key1 in data) {
			option_left3.yAxis[0].data.push(key1);
			var diskInfo = data[key1];
			for ( var key2 in diskInfo) {
				if (diskInfo[key2].diskUsedPer>parseInt(diskUsed)) {
						option_left3.series[$.inArray(key2, keys)].data.push(
								{
									value : diskInfo[key2].diskUsedPer,
									itemStyle : {
										normal : {
											color : '#c23531'
										}
									}
								});
						prompt(key1+ '&nbsp;服务器的'+ '磁盘' + key2+'分区的使用率已达到&nbsp;' +diskInfo[key2].diskUsedPer+'%');
						warnning+=key1+ '服务器的'+ '磁盘' + key2+'分区的使用率已达到' +diskInfo[key2].diskUsedPer+'%'+' ';
						warnMusic();
				}else {
					option_left3.series[$.inArray(key2, keys)].data.push(
							{
								value : diskInfo[key2].diskUsedPer,
								itemStyle : {
									normal : {
										color : option_left3.color[$.inArray(key2, keys)]
									}
								}
							});
				}
			}
		}
		left3Chart.setOption(option_left3);
	});
}

//得到CPU图表函数
function getCpuEcharts() {

	left1Chart = echarts.init(cpuUse);
	option_left1 = {
			color: ['#277ACE','#65f5f3'], //可选色：'#86D560', '#AF89D6', '#59ADF3', '#FF999A',
		// '#FFCC67'
		tooltip : {
			trigger : 'axis',
			axisPointer : { // 坐标轴指示器，坐标轴触发有效
				type : 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		grid : {
			x : '0',
			y : '3%',
			x2 : '3%',
			y2 : '10%',
			containLabel : true
		},
	    legend: {
	        data: ['CPU使用率','IOwait'],
	        itemWidth:11,
	        itemHeight:10,
			textStyle:{
				color:'#eee',
				fontSize:10,
			},
			top:'93%'
	    },
		xAxis : [ {
			type : 'category',
			data : [],
			splitLine : {
				"show" : false
			},
			axisTick : {
				"show" : false
			},
			splitArea : {
				"show" : false
			},
			axisLabel : {
				interval : 0,
				rotate : -33,
				margin : 26,
				align : 'center',
				show : true,
				splitNumber : 15,
				textStyle : {
					fontFamily : "微软雅黑",
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		yAxis : [ {
			type : 'value',
			min : 0,
			max : 100,
			splitLine : {
				lineStyle : {
					color : '#284190'
				}
			// show:false
			},
			axisLabel : {
				formatter : '{value}%',
				textStyle : {
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		series : [ {
			name : 'CPU使用率',
			type : 'bar',
			barWidth : '33%',
			barGap:0,
			data : [],
			label : {
				normal : {
					show : true,
					formatter : '{c}%',
					position: 'top',
					textStyle : {
						fontSize : 10
					}
				}
			},
		} ,
		{
			name : 'IOwait',
			type : 'bar',
			barWidth : '33%',
			barGap:0.2,
			data : [],
			label : {
				normal : {
					show : true,
					formatter : '{c}%',
					position: 'top',
					textStyle : {
						fontSize : 10
					}
				}
			},
		} ]
	};
}
// 得到 CPU数据
function getCpuInfo() {
	$.post('cpuInfo/getAllCpuinfo', {}, function(data) {
		var data = data.data;
		for ( var key in data) {
			option_left1.xAxis[0].data.push(key);
			if (data[key].used > parseInt(cpuUsed)) {
				option_left1.series[0].data.push({
					value : data[key].used,
					itemStyle : {
						normal : {
							color : '#c23531'
						}
					}

				});
				prompt(key+ '&nbsp;服务器的'+ 'CPU使用率已达到&nbsp;'+data[key].used+'%');
				warnMusic();
				warnning+=key+ '服务器的'+ 'CPU使用率已达到'+data[key].used+'%'+' ';
			} else {
				option_left1.series[0].data.push({
					value : data[key].used,
					itemStyle : {
						normal : {
							color : '#277ACE'
						}
					}
				});
			}
			if(data[key].iowaite > parseInt(cpuIowait)){
				option_left1.series[1].data.push({
					value : data[key].iowaite,
					itemStyle : {
						normal : {
							color : '#c23531'
						}
					}
				});
				prompt(key+ '&nbsp;服务器的'+ 'IO等待比例已达到&nbsp;'+data[key].iowaite+'%');
				warnMusic();
				warnning+=key+ '服务器的'+ 'CPU使用率已达到'+data[key].used+'%'+' ';
			}else {
				option_left1.series[1].data.push({
					value : data[key].iowaite,
					itemStyle : {
						normal : {
							color : '#65f5f3'
						}
					}
				});
			}
		}
		left1Chart.setOption(option_left1);
	});
	option_left1.xAxis[0].data.length = 0;
	option_left1.series[0].data.length = 0;
	option_left1.series[1].data.length = 0;
}
//得到内存echarts图表
function getMemEcharts() {
	left2Chart = echarts.init(memUse);
	option_left2 = {
		color: ['#277ACE','#65f5f3'], //可选色：'#86D560', '#AF89D6', '#59ADF3', '#FF999A',
		// '#FFCC67'
		tooltip : {
			trigger : 'axis',
			axisPointer : { // 坐标轴指示器，坐标轴触发有效
				type : 'shadow' // 默认为直线，可选为：'line' | 'shadow'
			}
		},
		grid : {
			x : '0',
			y : '3%',
			x2 : '3%',
			y2 : '10%',
			containLabel : true
		},
	    legend: {
	        data: ['内存使用率','SWAP使用率'],
	        itemWidth:11,
	        itemHeight:10,
			textStyle:{
				color:'#eee',
				fontSize:10,
			},
			top:'93%'
	    },
		xAxis : [ {
			type : 'category',
			data : [],
			splitLine : {
				"show" : false
			},
			axisTick : {
				"show" : false
			},
			splitArea : {
				"show" : false
			},
			axisLabel : {
				interval : 0,
				rotate : -33,
				margin : 26,
				align : 'center',
				show : true,
				splitNumber : 15,
				textStyle : {
					fontFamily : "微软雅黑",
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		yAxis : [ {
			type : 'value',
			min : 0,
			max : 100,
			splitLine : {
				lineStyle : {
					color : '#284190'
				}
			//show:false
			},
			axisLabel : {
				formatter : '{value}%',
				textStyle : {
					fontSize : 10,
					color : '#EEE',
				}
			},
		} ],
		series : [ {
			name : '内存使用率',
			type : 'bar',
			barWidth : '33%',
			barGap:0,
			data : [],
			itemStyle:{
				normal:{
					barBorderRadius: 50,
				}
			},
			label : {
				normal : {
					show : true,
					formatter : '{c}%',
					position : 'top',
					textStyle : {
						fontSize : 10
					}
				}
			},
		},
		{
			name : 'SWAP使用率',
			type : 'bar',
			barWidth : '33%',
			barGap:0.2,
			data : [],
			itemStyle:{
				normal:{
					barBorderRadius: 50,
				}
			},
			label : {
				normal : {
					show : true,
					formatter : '{c}%',
					position : 'top',
					textStyle : {
						fontSize : 10
					}
				}
			},
		} ]
	};
}
//得到内存数据
function getmemInfo() {
	$.post('MemInfo/getAllMeminfo', {}, function(data) {
		var data = data.data;
		for ( var key in data) {
			option_left2.xAxis[0].data.push(key);
			if (data[key].memUsed > parseInt(memUsed)) {
				option_left2.series[0].data.push({
					value : data[key].memUsed,
					itemStyle : {
						normal : {
							color : '#c23531'
						}
					}

				});
				prompt(key+ '&nbsp;服务器的'+ '内存使用率已达到&nbsp;'+data[key].memUsed+'%');
				warnMusic();
				warnning+=key+ '服务器的'+ '内存使用率已达到'+data[key].memUsed+'%'+' ';
			} else {
				option_left2.series[0].data.push({
					value : data[key].memUsed,
					itemStyle : {
						normal : {
							color : '#277ACE'
						}
					}
				});
			}
			if(data[key].swapUsed >parseInt(swapUsed)){
				option_left2.series[1].data.push({
					value : data[key].swapUsed,
					itemStyle : {
						normal : {
							color : '#c23531'
						}
					}

				});
				prompt(key+ '&nbsp;服务器的'+ 'SWAP使用率已达到&nbsp;'+data[key].swapUsed+'%');
				warnMusic();
				warnning+=key+ '服务器的'+ 'SWAP使用率已达到'+data[key].swapUsed+'%'+' ';
			}else {
				option_left2.series[1].data.push({
					value : data[key].swapUsed,
					itemStyle : {
						normal : {
							color : '#65f5f3'
						}
					}
				});
			}
		}
		left2Chart.setOption(option_left2);
	});
	option_left2.xAxis[0].data.length = 0;
	option_left2.series[0].data.length = 0;
	option_left2.series[1].data.length = 0;
}

//得到echarts画布
function getCanvas(name, position) {
	var canvas = document.createElement('div');
	canvas.innerHTML = '<div></div>';
	canvas.setAttribute('id', name);
	canvas.setAttribute('style', 'height:90%;margin-top: -4%');
	position.appendChild(canvas);
}
//得到jtopo画布
function getJtopoCanvas(name, position) {
	var canvas = document.createElement('canvas');
	canvas.innerHTML = '<canvas></canvas>';
	canvas.setAttribute('id', name);
	canvas.setAttribute('style', 'height:525px;width:776px;margin-top: -4%');
	position.appendChild(canvas);
}
//页面响铃报警
function warnMusic() {
	var music = document.getElementById('warnMusic');
	music.play();
	var times = 0;
	var interval = setInterval(function() {
		if(music.ended){
			music.load();
		}
		times += 1;
		if (times == 8) {
			clearInterval(interval);
		}
	}, 1000)
}
//页面提示框报警
function prompt(status) {
	str.options = {
		closeButton : true,
		progressBar : true,
		showMethod : 'slideDown',
		timeOut : 30000
	};
	toastr.warning(status);
}